package com.kaili.basic.controller.pda.v1;


import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.pojo.dto.BaseParameterControlAddDto;
import com.kaili.basic.pojo.dto.BaseParameterControlQueryDto;
import com.kaili.basic.pojo.entity.BaseParameterControl;
import com.kaili.basic.pojo.vo.BaseParameterControlVO;
import com.kaili.basic.service.IBaseParameterControlService;
import com.kaili.basic.version.ApiVersion;
import com.kaili.common.response.CommonStatus;
import com.kaili.common.response.RestStatus;
import com.kaili.common.util.LoginDetailUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 参数控制 前端控制器
 * </p>
 *
 * @author nigang
 * @since 2018-06-28
 */
@ApiVersion(1)
@RequestMapping("/{api_version}")
@RestController("baseParameterControlControllerP")
@Api(tags = "[pda]参数控制", description = "[pda]参数控制相关API")
public class BaseParameterControlController {
    @Autowired
    IBaseParameterControlService baseParameterControlService;

    @GetMapping(value = "p/parameterControl/byCompany")
    @ApiOperation(value = "查参数控制", notes = "根据登录的网点和用户查询参数控制")
    public BaseParameterControlVO getParameterByCompany(){
        BaseParameterControlVO controlVO=new BaseParameterControlVO();
        BaseParameterControl control = baseParameterControlService.getParameterByCompany();
        if (control != null ) {
            if (control.getCollectionCharge() == null || control.getCollectionCharge() == 0) {
                control.setCollectionCharge(2.00);
            }
            if (control.getNormalGoodsPremiumRate() == null || control.getNormalGoodsPremiumRate() == 0) {
                control.setNormalGoodsPremiumRate(2.00);
            }
            if (control.getFragilePremiumRate() == null || control.getFragilePremiumRate() == 0) {
                control.setFragilePremiumRate(2.00);
            }
            BeanUtils.copyProperties(control,controlVO);
            return controlVO;
        }else {
            BaseParameterControl baseParameterControl = new BaseParameterControl();
            baseParameterControl.setCollectionCharge(2.00);
            baseParameterControl.setNormalGoodsPremiumRate(2.00);
            baseParameterControl.setFragilePremiumRate(2.00);
            BeanUtils.copyProperties(baseParameterControl,controlVO);
            return controlVO;
        }

    }
}

